package com.liziyi0914.morearmor.effect;

import com.liziyi0914.morearmor.Utils;
import com.liziyi0914.morearmor.event.Listener;
import com.liziyi0914.morearmor.event.entity.EntityDamageEvent;
import net.minecraft.entity.LivingEntity;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.Items;
import net.minecraft.server.world.ServerWorld;

import java.util.function.Predicate;

/**
 * 2021/6/29<br>
 * MoreArmor<br>
 *
 * @author huanmeng_qwq
 */
public class WaterBucketEffect extends AbstractEffect {
    @Listener
    public void onFall(EntityDamageEvent e) {
        if (!e.getSource().isFromFalling() || !predicateArmor().test(e.getEntity())) {
            return;
        }
        if (e.getEntity().getEntityWorld() instanceof ServerWorld world) {
            world.setBlockState(e.getEntity().getBlockPos(), Fluids.WATER.getDefaultState().getBlockState());
            e.setCanceled(true);
        }
    }
    @Override
    public Predicate<LivingEntity> predicateArmor() {
        return Utils.hasItemArmor(Items.WATER_BUCKET);
    }
}
